package org.example.curriculum_design_6_16.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.curriculum_design_6_16.entity.pojo.CompetitionCatalog;
import org.example.curriculum_design_6_16.entity.vo.Result;
import org.example.curriculum_design_6_16.service.CompetitionCatalogService;
import org.example.curriculum_design_6_16.mapper.CompetitionCatalogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 郑凯
 * @description 针对表【competition_catalog】的数据库操作Service实现
 * @createDate 2025-06-22 21:30:17
 */
@Service
public class CompetitionCatalogServiceImpl extends ServiceImpl<CompetitionCatalogMapper, CompetitionCatalog>
        implements CompetitionCatalogService{

    @Autowired
    private CompetitionCatalogMapper competitionCatalogMapper;

    @Override
    public int addCompetition(CompetitionCatalog competitionCatalog) {
        return competitionCatalogMapper.insert(competitionCatalog);
    }

    @Override
    public int updateCompetition(CompetitionCatalog competitionCatalog) {
        return competitionCatalogMapper.update(competitionCatalog);
    }

    @Override
    public int deleteCompetition(Integer id) {
        return competitionCatalogMapper.delete(id);
    }

    @Override
    public CompetitionCatalog getCompetitionById(Integer id) {
        CompetitionCatalog catalog = competitionCatalogMapper.selectById(id);
        if (catalog == null) throw new RuntimeException("未找到ID为" + id + "的竞赛目录");
        return catalog;
    }

    @Override
    public CompetitionCatalog getCompetitionByName(String competitionName) {
        CompetitionCatalog catalog = competitionCatalogMapper.selectByName(competitionName);
        if (catalog == null) throw new RuntimeException("未找到competitionName为" + competitionName + "的竞赛目录");
        return catalog;
    }

    @Override
    public List<CompetitionCatalog> getAllCompetitions() {
        return competitionCatalogMapper.selectAll();
    }

    @Override
    public List<CompetitionCatalog> getCompetitionsByLevelAndCategory(String level, String category) {
        return competitionCatalogMapper.selectByLevelAndCategory(level, category);
    }
}